package com.tianqu.tms.www.car.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.www.car.controller.CarSearchMarketDetailController;
import com.tianqu.tms.www.car.viewhelper.CarCreationInputViewHelper;

/**
 * @author zhangxueliang
 * 高级搜索中车辆的基本详细action
 */
public class CarSearchMarketDetailAction extends TmsAction{
	private Logger logger = Logger.getLogger(CarSearchMarketDetailAction.class);
	public static final String SERIAL = "serial";
	public static final String LINKFLAG = "linkFlag";
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		String serial = "";
		if(request.getParameter("serial")!=null && !"".equals(request.getParameter("serial")))
		{
			serial = request.getParameter("serial");		
		}else{
			serial = (String)uc.getAttribute(SERIAL);
		} 
		
	
		uc.setAttribute(SERIAL, serial);
		CarSearchMarketDetailController controller = new CarSearchMarketDetailController();
		controller.execute(uc);
		
		CarCreationInputViewHelper carCreationInputViewHelper = (CarCreationInputViewHelper)uc.getAttribute(TmsConstants.VIEWHELP);
		if(carCreationInputViewHelper.getAttestStatus() == 2){
			carCreationInputViewHelper.setZcFlag("on");
		}else{
			carCreationInputViewHelper.setZcFlag("off");
		}
		String flagTo = "0";
		if(request.getParameter("flag")!=null && !"".equals(request.getParameter("flag"))){
			flagTo = request.getParameter("flag");
			uc.setAttribute(LINKFLAG, flagTo);
		}else {
			flagTo = (String)uc.getAttribute(LINKFLAG);
		}
		carCreationInputViewHelper.setFlagTo(flagTo);
		if(uc.getAttribute("countAll")!= null){
			int countAll = (Integer)uc.getAttribute("countAll");
//			int countProxy = (Integer)uc.getAttribute(MemberCarInMarketTopController.COUNTPROXY);
			carCreationInputViewHelper.setCountAll(countAll);
//			carCreationInputViewHelper.setCountProxy(countProxy);
		}
		//向viewhelp中放一个字符串
		carCreationInputViewHelper.setPrintText((String)uc.getAttribute("printText"));
		carCreationInputViewHelper.setSoldOurPrintFlag((String)uc.getAttribute("soldOurPrintFlag"));
		carCreationInputViewHelper.setInnerSoldFlag((String)uc.getAttribute("innerSoldFlag"));
		uc.removeAttribute("printText");
		uc.removeAttribute("soldOurPrintFlag");
		uc.removeAttribute("innerSoldFlag");
		
		request.setAttribute(VIEWHELP, carCreationInputViewHelper);
		logger.debug(this.getClass().getName() + "#execute was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
